import MusicManager from "../../../MusicManager";
import { Killer } from "../../funcObj/interface/HealthPoint";
import Player from "../../player/Player";
import DestructibleFacility from "../DestructibleFacility";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Atm extends DestructibleFacility {

    @property(cc.Animation)
    anima: cc.Animation = null;

    init(player: Player): void {
        super.init(player);
        this.schedule(this.addResource, 0.7, cc.macro.REPEAT_FOREVER);
        this.player.node.on(Player.EventType.击毁敌方飞行物, this.addWreckResourse, this);
    }

    addResource() {
        MusicManager.instance.play(MusicManager.instance.Atm, this.node);
        this.player.addDiamond(1, this.node.position);
    }

    addWreckResourse() {
        MusicManager.instance.play(MusicManager.instance.Atm, this.node);
        this.player.addDiamond(10, this.node.position);
        this.anima.play();
    }

    die(killer: Killer): void {
        super.die(killer);
        this.unscheduleAllCallbacks();
    }

}
